package com.aabte.auth.role.domain.event;

import com.aabte.auth.role.domain.model.RoleId;
import com.aabte.auth.role.domain.model.RoleName;
import com.aabte.commons.ddd.shared.DomainEvent;
import lombok.Getter;
import lombok.ToString;

import java.util.Objects;
import java.util.UUID;

@Getter
@ToString
public class RoleCreated implements DomainEvent<RoleCreated, String> {

    private final String eventId;
    private final RoleId roleId;
    private final RoleName roleName;

    public RoleCreated(RoleId roleId, RoleName roleName) {
        this.eventId = UUID.randomUUID().toString().replaceAll("-", "");
        this.roleId = roleId;
        this.roleName = roleName;
    }

    @Override
    public boolean sameIdentityAs(RoleCreated groupCreated) {
        return this.eventId.equals(groupCreated.eventId);
    }

    @Override
    public String identity() {
        return this.eventId;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        RoleCreated that = (RoleCreated) o;
        return eventId.equals(that.eventId);
    }

    @Override
    public int hashCode() {
        return Objects.hash(eventId);
    }
}
